local Players = game:GetService("Players")
local lp = Players.LocalPlayer
local pg = lp and lp:WaitForChild("PlayerGui", 10)
if not pg then
    warn("PlayerGui not found")
    return
end

local ok, root = pcall(function()
    return pg:WaitForChild("MainGUI", 10)
        :WaitForChild("Game", 10)
        :WaitForChild("Leaderboard", 10)
        :WaitForChild("Container", 10)
end)
if not ok or not root then
    warn("Path to ToggleRequests root not found")
    return
end

local toggle = root:FindFirstChild("ToggleRequests") or root:WaitForChild("ToggleRequests", 5)
if not toggle then
    warn("ToggleRequests not found under root; children:")
    for _,c in ipairs(root:GetChildren()) do print("-", c.Name, c.ClassName) end
    return
end

local onBtn  = toggle:FindFirstChild("On")
local offBtn = toggle:FindFirstChild("Off")
if not onBtn or not offBtn then
    warn("On/Off button not found; ToggleRequests children:")
    for _,c in ipairs(toggle:GetChildren()) do print("-", c.Name, c.ClassName) end
end

local function bind(btn)
    if not btn then return end
    if btn.Activated then btn.Activated:Connect(function() print("ToggleRequests Activated:", btn.Name) end) end
    if btn.MouseButton1Click then btn.MouseButton1Click:Connect(function() print("ToggleRequests Click:", btn.Name) end) end
end
bind(onBtn)
bind(offBtn)

-- 切 OFF：依据可见性/交互性判断
if offBtn and (offBtn.Visible ~= false) and (offBtn.AutoButtonColor ~= nil) then
    pcall(function() offBtn:Activate() end)
    print("ToggleRequests -> OFF")
elseif offBtn then
    offBtn.Visible = true
    onBtn.Visible = false
    pcall(function() offBtn:Activate() end)
    print("ToggleRequests -> OFF (forced)")
else
    warn("No offBtn; cannot toggle visually. Trying SetRequestsEnabled via remote is recommended.")
end